*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

include directories.do


*********** CONTIGUOUS PAIR SPECIFICATIONS FOR (5) AND (6) OF DLR'S TABLE 2 *****
*********** FOR BOTH COUNTY-PAIRS AND MULTI-STATE CZONES ************************
*********** EXTRACT FROM DLR'S "MAIN ANALYSIS 11-6-09.DO" ***********************


drop _all 

set more off

foreach d in "co" "cz" {

use "`dlrdir'`s'QCEWindustry_minwage_contig_`d'.dta", clear

**

*TO CORRECT DRL'S STANDARD ERRORS IN COUNTY-PAIR REGRESSIONS (PAIRTIMES==2)
merge m:1 pair_id using "`dlrdir'`s'`d'_pairs_dlr.dta"

drop if _merge==2
drop _merge

*keep if pairtimes==2 
**

egen pair_id_num = group(pair_id)
gen sample_5 = 1
gen absorb_5 = period
gen sample_6 = 1
egen absorb_6 = group(pair_id period)

sort  pair_id period
 
gen state_a = real(substr(pair_id, 1,2))
gen state_b = real(substr(pair_id, 7,2))

gen st_min = min( state_a, state_b)
gen st_max = max(state_a, state_b)
egen bordersegment = group(st_min st_max)


*K loops through industries .

foreach k in rest_both  {


forval specification = 5/6 {

*population controls 
eststo m1_emp_`specification'_`d': reghdfe lnemp_`k' lnMW lnpop if sample_`specification'==1 & nonmissing_`k'==66, cluster(state_fips bordersegment) absorb(county absorb_`specification')

eststo m1_AWW_`specification'_`d': reghdfe lnAWW_`k' lnMW if sample_`specification'==1 & nonmissing_`k'==66, cluster(state_fips bordersegment) absorb(county absorb_`specification')


* Population & Total Employment Controls*

eststo m2_emp_`specification'_`d': reghdfe lnemp_`k' lnMW lnpop lnemp_TOT if sample_`specification'==1 & nonmissing_`k'==66, cluster(state_fips bordersegment) absorb(county absorb_`specification')

eststo m2_AWW_`specification'_`d': reghdfe lnAWW_`k' lnMW lnAWW_TOT if sample_`specification'==1 & nonmissing_`k'==66, cluster(state_fips bordersegment) absorb(county absorb_`specification')


}

}
}
/* Print results */


tempfile specs


#delimit ;
esttab m1_emp_5_co m2_emp_5_co m1_emp_6_co m2_emp_6_co using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("CBCP-employment") ///
	keep(lnMW)
    nonotes ///
    label ///
    stats(N, labels("N") fmt(0))
    replace;
#delimit cr

#delimit ;
esttab m1_AWW_5_co m2_AWW_5_co m1_AWW_6_co m2_AWW_6_co using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("CBCP-earnings") ///
	keep(lnMW)
    nonotes ///
    label ///
	stats(N, labels("N") fmt(0))
    append;
#delimit cr

#delimit ;
esttab m1_emp_5_cz m2_emp_5_cz m1_emp_6_cz m2_emp_6_cz  using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("MSCZP-employment") ///
	keep(lnMW)
    nonotes ///
    label ///
	stats(N, labels("N") fmt(0))
    append;
#delimit cr

#delimit ;
esttab m1_AWW_5_cz m2_AWW_5_cz m1_AWW_6_cz m2_AWW_6_cz using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("MSCZP-earnings") ///
	keep(lnMW)
    nonotes ///
    label ///
	stats(N, labels("N") fmt(0))
    append;
#delimit cr

insheet using "`specs'.csv", comma clear
export excel "`outdir'`s'TablesJNR.xlsx", sheetreplace sheet(Table1_reghdfe)


clear all




